<template>
  <div class="home">
    <Swiper :swiper_img="banner"></Swiper>
    
    <div class="channel">
      <div class="content" v-for="(item,index) in channel" :key="index" @click="current=index,getCartory(item.url)" :class="index == current? 'classOn':'' ">
        <img :src="item.icon_url" alt="">
        <div class="title">{{item.name}} </div>
      </div>
    </div>

    <!-- select windows -->
    <div class="contont">
      <div class="left">
        <div class="left_item" v-for="(item,index) in categorylist" :key="index" 
         @click="categoryHandle(item.id),selRight=index" :class="selRight == index?'selCategory':'' ">
          <span>{{item.name}}</span>

        </div>
      </div>
      <!-- 产品展示 -->
      <div class="right">
        <div class="content" v-for="(item,index) in goodslist" :key="index" @click="sendGoods(item.id)">
          <div class="pls">
            <img :src="item.list_pic_url" alt="">
          </div>
          <!-- 产品描述 -->
          <div class="desc">
           <div class="title">{{item.name}}</div>

          </div>
        </div>

      </div>
    </div>
    


    
  </div>
</template>

<script>
import Swiper from '../../components/swiper/';
// @ is an alias to /src

export default {
  name: 'Home',
  data(){
    return{
      banner:[],
      channel:[],
      current:-1,
      categorylist:[],
      /* 右列表选中 */
      selRight:'',
      goodslist:[]
      
    }
  },
  components: {
    Swiper
  },
  mounted(){
    this.reqBanner()
    this.reqChannel()
  },
  methods:{

    /* 获取Banner */
    reqBanner(){
      this.$api.getBanner().then(res=>{
        const {data} = res
       
        if(data.status != 200){
          console.log('服务器链接超时');
        }else{
          this.banner = data.data
        }
      })
    },
    /* channel */
    reqChannel(){
      this.$api.getChannel().then(res=>{
         const {data} = res
       
        if(data.status != 200){
          console.log('服务器链接超时');
        }else{
          this.channel = data.data
        }
      })
    },
    /* 点击获取类目 */
    getCartory(url){
      this.categorylist = []
      this.goodslist = []
      this.selRight = -1

      const cartoryId = url.replace('?id=',' ')
      var i = cartoryId.split(' ')
      const categoryid = i[1]
      
      this.$api.getCategory({params:{
        categoryid}
      }).then(res=>{
        this.categorylist = res.data.data
      })
    },
    /* 点击右分类列表 */
    categoryHandle(goods){
      this.$api.getGoodsList({params:{
        goods
      }}).then(result =>{
        this.goodslist = result.data.data
      })
    },

    /* 发送产品ID */
    sendGoods(id){
      this.$router.push(`/goods/${id}`)
    }
  
  }
}
</script>

<style lang="less" scoped>
.channel{
  height: 172px;
  display: flex;
  .content{
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;

    width: 100%;
    box-sizing: border-box;

    img{
      color: var(--themeColor);
      width: 90px;
      text-align: center;
    }

  }
  .classOn{
    
    background-color:rgb(219, 229, 233);

  }
  border-bottom: 1px solid #bebebe;
}

/* 分类框 */
.contont{
  box-sizing: border-box;
  display: flex;
  height: 600px;
  
  .left{
    margin-bottom: 17px;
    overflow: scroll;
    width: 50px;
    font-size: 28px;
    font-weight: 800;
    color: #888787;
    
   
    background-color: rgb(245, 245, 245);
    display: flex;
    flex:3;
    // justify-content: center;
    // border:1px solid red;
    flex-direction: column;
    :nth-child(n-1){
      flex:1;
      white-space: nowrap;
      text-overflow: ellipsis;
       overflow: hidden;
       line-height: 70px;
    }
    .left_item{
      line-height: 60px;

    }
    span{
      width: 200px;
      margin: auto 20px;
      text-overflow: hide;

      }
    .selCategory{
    background-color: rgb(255, 215, 215);
    font-size: 33px;
    border-right: rgb(252, 97, 77) 5px solid;
       }

   }

  }
  .right{
    padding: 0 20px;
    overflow: scroll;
    flex:10;
    .content{
      border-bottom: 1px solid #e4e4e4;
      display: flex;
      .pls{
        flex:4;
         img{
        width: 100%;

        }
      }
      .desc{
      padding: 10px;
      margin: auto 0;


        flex:8;
      }
     
    }
 
}
</style>
